﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SuperX.Helper.PageBreak
{
    public class DataPaging
    {
        /// <summary>
        /// 分页处理
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pageResult"></param>
        /// <returns></returns>
        public static PageResult<T> SplitList<T>(PageResult<T> pageResult)
        {
            var _pageResult = pageResult.Rows.Skip((pageResult.PageNo - 1) * pageResult.PageSize).Take(pageResult.PageSize).ToList();
            var _totalRows = (int)Math.Ceiling(Convert.ToDecimal(pageResult.Rows.Count) / pageResult.PageSize);
            PageResult<T> res = new PageResult<T>()
            {
                PageNo = pageResult.PageNo,
                PageSize = pageResult.PageSize,
                TotalPage = _totalRows,
                TotalRows = pageResult.Rows.Count,
                Rows = _pageResult,
            };
            return res;
        }
    }
}